package cn.aitrox.ry.service.anno.dao.impl;

import cn.aitrox.ry.common.dao.MapperSqlCallback;
import cn.aitrox.ry.common.dao.impl.BaseDaoImpl;
import cn.aitrox.ry.service.anno.dao.TaskCompanyDao;
import cn.aitrox.ry.service.anno.entity.TaskCompanyEntity;
import cn.aitrox.ry.service.anno.mapper.TaskCompanyMapper;
import cn.aitrox.ry.util.ArrayUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

@Repository
public class TaskCompanyDaoImpl extends BaseDaoImpl<TaskCompanyEntity> implements TaskCompanyDao {

    @Autowired
    private TaskCompanyMapper mapper;

    @Override
    public List<TaskCompanyEntity> findByTaskIds(List<Integer> taskIdList) {
        if(ArrayUtil.isEmpty(taskIdList)) {
            return new ArrayList<>();
        }
        return mapper.findByTaskIds(taskIdList);
    }

    @Override
    public List<TaskCompanyEntity> findByTaskId(Integer taskId) {
        TaskCompanyEntity cond = new TaskCompanyEntity();
        cond.setTaskId(taskId);
        return findByCondition(cond,null);
    }

    @Override
    public void batchSave(List<TaskCompanyEntity> list) {
        batchInsert(list, 1000, new MapperSqlCallback<TaskCompanyEntity>() {
            @Override
            public void batchInsert(List<TaskCompanyEntity> objList) {
                mapper.batchInsert(objList);
            }
        });
    }

    @Override
    public void deleteByTaskId(Integer taskId) {
        // 条件删除必须使用sql
        mapper.deleteByTaskId(taskId);
    }
}
